package cc.smarnet.caihou.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import java.util.List;

import cc.smarnet.caihou.R;

public class PackingSpecificationsAdapter extends BaseAdapter {
    private Context context;
    private List<String> list;
    private int temPosition = 0;// 默认第一个元素为选择的元素

    public PackingSpecificationsAdapter(Context context,List<String> list){
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        PackingSpecificationsViewHold viewHold = null;
        view=View.inflate(context, R.layout.packing_specifications_item,null);
        viewHold=new PackingSpecificationsViewHold();
        viewHold.button=view.findViewById(R.id.packing_specifications_item_button);
        if (temPosition==i){
            viewHold.button.setText(list.get(i));
            viewHold.button.setBackgroundResource(R.drawable.gridview_button_select);
            viewHold.button.setTextColor(Color.WHITE);
        }else {
            viewHold.button.setText(list.get(i));
            viewHold.button.setBackgroundResource(R.drawable.gridview_button_not_select);
        }
        return view;
    }
    public void setSelection(int position) {
        temPosition = position;
    }
}

class PackingSpecificationsViewHold {
    Button button;
}